package com.jevons.muffin.net.exception;

import java.io.IOException;

/**
 * 自定义返回结果错误
 * @author linaisheng
 * Created at 2019/3/14.
 */

public class ResponseException extends IOException {

    private int errorCode;
    private String description;

    private boolean isHttpError =false;

    private Throwable throwable;

    public ResponseException(Throwable throwable) {
        this(1001, throwable.getMessage(), throwable);
    }

    public ResponseException(String description, Throwable throwable) {
        this(1001, description, throwable);
    }

    public ResponseException(String description, Throwable throwable, boolean isHttpError) {
        this(1001, description, throwable, isHttpError);
    }

    public ResponseException(int errorCode, String description, Throwable throwable) {
        this(errorCode, description, throwable, false);
    }

    public ResponseException(int errorCode, String description, Throwable throwable, boolean isHttpError) {
        this.errorCode = errorCode;
        this.description = description;
        this.throwable = throwable;
        this.isHttpError = isHttpError;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public String getDescription() {
        return description;
    }

    @Override
    public String getMessage() {
        return description;
    }

    public String getThrowableMessage() {
        return super.getMessage();
    }

    public Throwable getThrowable() {
        return throwable;
    }

    public boolean isHttpError() {
        return isHttpError;
    }

    @Override
    public void printStackTrace() {
        if (throwable != null) {
            throwable.printStackTrace();
        }
    }
}
